package com.ly.listener;

import com.ly.bean.EasybuyUser;
import com.ly.bean.Result;
import com.ly.service.MailService;
import com.ly.util.QueueNameUtil;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.amqp.rabbit.annotation.RabbitHandler;
import org.springframework.amqp.rabbit.annotation.RabbitListener;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import java.util.Map;

/**
 * @author 李岩
 * @date 2022/1/11-9:17
 * @describe
 */
@Component
@RabbitListener(queues = QueueNameUtil.DIRECT_QUEUE_NAME_EMAIL) //监听的队列名称 TestQueue
public class DirectEmailListener {
    private final Logger logger= LoggerFactory.getLogger(DirectEmailListener.class);
    private DirectEmailListener(){
        System.out.println("进入到 DirectEmailListener 的 email");
    }

    @Autowired
    private MailService mailService;

    @RabbitHandler
    public void process(Map obj){
        logger.info("DirectEmailListener 消费者收到发送邮件的信息: " + obj);
        EasybuyUser user =(EasybuyUser) obj.get("user");
        String content =(String) obj.get("content");
        Result result = mailService.sendHtmlMail(user.getEmail(), "易买网激活码", content);
        logger.info("发送邮件的结果  "+result);
    }
}
